package com.example.waterdispenserm2.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;

import com.example.waterdispenserm2.util.SPUtils;
import com.example.waterdispenserm2.adapter.M2Adapter;
import com.example.waterdispenserm2.base.BasicsActivity;
import com.example.waterdispenserm2.bean.M2UIItem;
import com.example.waterdispenserm2.databinding.ActivityNoodleBinding;
import com.example.waterdispenserm2.dp.M2NoodleHelperUtil;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

//模版
public class NoodleActivity extends BasicsActivity<ActivityNoodleBinding> {

    public static  void startActivity(){
        Intent intent=new Intent(SPUtils.getContext(), NoodleActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        SPUtils.getContext().startActivity(intent);
    }


    private final List<M2UIItem> listData=new ArrayList<>();
    M2Adapter adapter;
    @Override
    public void widgetClick(View v) {

    }

    @Override
    public void setListener() {

    }

    @Override
    public void initView() {
        binding.rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        adapter=new M2Adapter(listData,this);
        binding.lvNoodle.setAdapter(adapter);
        binding.lvNoodle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                NoodleSetActivity.startActivity(listData.get(position),position);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        listData.clear();
        listData.addAll(M2NoodleHelperUtil.getInstance().getSQ());
        adapter.notifyDataSetChanged();
    }

    @Override
    protected ActivityNoodleBinding getViewBinding() {
        return ActivityNoodleBinding.inflate(LayoutInflater.from(this));
    }
}